<template>

<h2>添加会员</h2>


<table class="table table-border">
<thead>


    <tr>
        <th>
            会员名称
        </th>

        <th>
            <input type="text" v-model="nn.mname">
        </th>
    </tr>

    <tr>
        <th>
            会员手机号
        </th>

        <th>
            <input type="text"  v-model="nn.phone">
        </th>
    </tr>

    <tr>
        <th>
            会员密码
        </th>

        <th>
            <input type="password"  v-model="nn.mpwd">
        </th>
    </tr>


    <tr>
        <th>
            会员生日
        </th>

        <th>
            <input type="date"  v-model="nn.shengRi">
        </th>
    </tr>


    <tr>
        <th>
            会员身份证
        </th>

        <th>
            <input type="text"  v-model="nn.shenFenZheng">
        </th>
    </tr>


    <tr>
        <th>
            会员会员卡号
        </th>

        <th>
            <input type="text"  v-model="nn.huiYuanKa">
        </th>
    </tr>


    <tr>
        <th>
            等级
        </th>

        <th>
           <select  v-model="nn.did" >
                <option :value="-1">--请选择---</option>
                <option  v-for="item in ab" :value="item.dId" >{{ item.dName }}</option>
           </select>
        </th>
    </tr>



    <tr>
        <th>
           
        </th>

        <th>
      
            <button @click="AddMe" value="添加">添加</button>
          
        </th>
    </tr>

</thead>
    
</table>




<tbody>

  
</tbody>


</template>


<script setup lang="ts">

const ab= ref([{


    dId: -1,
    dName: "--请选择---"


}])

import axios from 'axios';
import {onMounted, ref}  from'vue';
import{useRouter,createRouter} from 'vue-router'

    onMounted(()=>{

        XiaLa()


    })


    const router = useRouter();
    const XiaLa=()=>{
            axios.get('https://localhost:7010/api/DengJI/ShowDj').then(res=>{

                    
                ab.value=res.data;
            })
            .catch(error=>{
                   
                console.log(error);
            })

    }


const nn =ref({

 mId: 0,
  mname: "",
  phone: "",
  mpwd: "",
  shengRi: "",
  shenFenZheng: "",
  huiYuanKa: "",
  did: -1

})




  
const AddMe =()=>{

    axios.post('https://localhost:7010/api/Member/AddMe',nn.value).then(res=>{

        if(res.data>0)
    {
        alert('添加成功')
        router.push('/ShowMember')

    
    }
    else if(res.data==-1)
    {
        alert('身份证号重复')
    }
    else
    {
        alert('添加失败')
    }
    
        


    }).catch(x=>{

        console.log(x.data);
        })


}





</script>